package com.geeguo.ebuilder.core.common.dictionary;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;

public enum GenderEnum implements IDictionary {

    Male(1, "男"),
    Female(2, "女");

    private int    value;
    private String label;

    GenderEnum(int value, String label) {
        this.value = value;
        this.label = label;
    }

    @Override
    public int getValue() {
        return value;
    }

    @Override
    public String getLabel() {
        return label;
    }

    public static List<GenderEnum> getEnumValues() {
        return Arrays.asList(values());
    }
    
    public static GenderEnum parse(int value) {
        for (GenderEnum item : GenderEnum.values()) {
            if (value == item.getValue()) {
                return item;
            }
        }
        return null;
    }

    public static GenderEnum parse(String label) {
        if (StringUtils.isNotEmpty(label)) {
            for (GenderEnum item : GenderEnum.values()) {
                if (label.equals(item.getLabel())) {
                    return item;
                }
            }
        }
        return null;
    }
}